package cn.hdustea.shopNavigation.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import cn.hdustea.shopNavigation.MainActivity
import cn.hdustea.shopNavigation.R
import cn.hdustea.shopNavigation.WNaviGuideActivity
import cn.hdustea.shopNavigation.entity.Beauty
import cn.hdustea.shopNavigation.ui.view.SearchActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import kotlinx.android.synthetic.main.item_list_amusement.view.*
import kotlinx.android.synthetic.main.item_list_beauty.view.*
import kotlinx.android.synthetic.main.item_list_beauty.view.rt_bar
import kotlinx.android.synthetic.main.item_list_beauty.view.to_navigation
import kotlinx.android.synthetic.main.item_list_food.view.*

/**
 * <pre>
 *     author : HuQiang
 *     time   : 2020/09/21
 *     desc   :
 *     version: 1.0
 * </pre>
 */
class BeautyItemAdapter(layoutRes: Int, parentContext: Context) :
        BaseQuickAdapter<Beauty, BaseViewHolder>(layoutRes), LoadMoreModule {

    val pContext = parentContext

    private val OPTIONS: RequestOptions = RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .dontAnimate()


    override fun convert(holder: BaseViewHolder, item: Beauty) {
        val rootView = holder.itemView
        rootView.tv_beauty_room_name.text = item.name
        rootView.rt_bar.rating = item.stars
        if (item.consume_per == 0) {
            rootView.tv_beauty_average_price.visibility = View.GONE
        } else {
            rootView.tv_beauty_average_price.text =
                    String.format(context.resources.getString(R.string.food_price), item.consume_per)
            rootView.tv_beauty_average_price.visibility = View.VISIBLE
        }
        rootView.tv_beauty_type.text = item.tag
        if (item.picurls.size >= 1) {
            Glide.with(context).load(item.picurls[0]).apply(OPTIONS).into(rootView.iv_beauty_1)
            if (item.picurls.size >= 2) {
                Glide.with(context).load(item.picurls[1]).apply(OPTIONS).into(rootView.iv_beauty_2)
                if (item.picurls.size >= 3) {
                    Glide.with(context).load(item.picurls[2]).apply(OPTIONS).into(rootView.iv_beauty_3)
                }
            }
        }
        rootView.to_navigation.setOnClickListener {
            val intent  = Intent(pContext, MainActivity::class.java)
            intent.putExtra("searchText", rootView.tv_beauty_room_name.text.toString())
            pContext.startActivity(intent)
        }

        Glide.with(context).load(R.drawable.ic_navigation).apply(OPTIONS).into(rootView.to_navigation)


    }
}